<!-- 系统日志列表信息 -->
<template>
  <div class="table">
    <div class="container">
      <div class="crumbs">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item> <i class="el-icon-search"></i> 查询条件： </el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <el-row :gutter="10">
        <el-col :xl="6" :lg="6" :md="12" :sm="24" class="mb10">
          <el-input v-model.trim="searchCondition.ip" placeholder="ip" clearable></el-input>
        </el-col>
        <el-col :xl="6" :lg="6" :md="12" :sm="24" class="mb10">
          <el-select v-model.trim="searchCondition.type" placeholder="操作类型" clearable>
            <el-option v-for="item in masterLogType" :label="item.dictLabel" :value="item.dictValue" :key="item.id"></el-option>
          </el-select>
        </el-col>
        <el-col :xl="6" :lg="6" :md="12" :sm="24" class="mb10">
          <el-input v-model.trim="searchCondition.info" placeholder="操作信息" clearable></el-input>
        </el-col>
        <el-col :xl="6" :lg="6" :md="12" :sm="24" class="mb10">
          <el-input v-model.trim="searchCondition.mobile" placeholder="手机号" clearable></el-input>
        </el-col>
        <el-col :xl="6" :lg="6" :md="12" :sm="24" class="mb10">
          <el-space wrap>
            <el-button type="success" :icon="Search" :disabled="disabledbtn" @click="searchInfo">搜索</el-button>
            <el-button type="warning" :icon="Refresh" :disabled="disabledbtn" @click="resetSearch">重置</el-button>
          </el-space>
        </el-col>
      </el-row>
      <div class="crumbs">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item><i class="el-icon-lx-cascades"></i>查询结果：</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <el-table :data="tableList" border class="table" ref="multipleTable" v-loading="loading">
        <el-table-column type="index" align="center"> </el-table-column>
        <el-table-column prop="ip" label="ip" align="center"> </el-table-column>
        <el-table-column prop="type_name" label="操作类型" align="center"> </el-table-column>
        <el-table-column prop="info" label="操作信息" align="center"> </el-table-column>
        <el-table-column prop="master.user_name" label="用户名" align="center"> </el-table-column>
        <el-table-column prop="master.mobile" label="手机号" align="center"> </el-table-column>
        <el-table-column prop="master.nick_name" label="昵称" align="center"> </el-table-column>
        <el-table-column prop="add_time" label="创建时间" align="center" :formatter="(row: IMasterLog) => handleVerifyFormatDate(row.add_time)"> </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          layout="total, sizes, prev, pager, next, jumper"
          :page-size="searchCondition.size"
          :current-page="searchCondition.current"
          :page-sizes="[10, 20, 30, 40, 50, 100]"
          :total="total"
          :hide-on-single-page="false">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts" name="masterLogInfo">
import { Search, Refresh } from "@element-plus/icons-vue";
import { handleVerifyFormatDate } from "@/utils/utils";
import { useDictData } from "@/hooks/network/useDictData";
import { useState } from "@/hooks/useState";
import type { IDictData } from "@/types/dict";
import type { IMasterLog, ISearchMasterLog } from "@/types/masterLog";
import { getMasterLogInfo } from "@/utils/api/masterLog";
const { disabledbtn, loading, toggleState } = useState();

const total = ref(0);
const searchCondition = reactive<ISearchMasterLog>({
  ip: "",
  type: "",
  info: "",
  mobile: "",
  current: 1,
  size: 20
});
const tableList = ref<Array<IMasterLog>>([]);
const masterLogType = ref<Array<IDictData>>([]);

/* 搜索 */
function searchInfo() {
  searchCondition.current = 1;
  searchCondition.size = 20;
  getTableInfo();
}

/**
 * 重置搜索内容
 */
function resetSearch() {
  searchCondition.ip = "";
  searchCondition.type = "";
  searchCondition.info = "";
  searchCondition.mobile = "";
  searchInfo();
}
/* 显示第几页 */
function handleCurrentChange(val: number) {
  searchCondition.current = val;
  getTableInfo();
}

/* 每页显示几条 */
function handleSizeChange(val: number) {
  searchCondition.size = val;
  getTableInfo();
}

/* 请求：获取表格中数据 */
function getTableInfo() {
  toggleState(true);
  getMasterLogInfo<IMasterLog, ISearchMasterLog>(searchCondition)
    .then(res => {
      tableList.value = res.result.data;
      total.value = res.result.total;
    })
    .finally(() => {
      toggleState(false);
    });
}

let { getDictData } = useDictData();
getDictData("MASTER_LOG_TYPE", masterLogType);
onMounted(() => {
  getTableInfo();
});
</script>

<style lang="scss" scoped>
/* layout-布局 */
.el-row:last-child {
  margin-bottom: 0;
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}

.handle-box {
  margin-bottom: 20px;
}

.handle-select {
  width: 120px;
}

.handle-input {
  width: 300px;
  display: inline-block;
}
.del-dialog-cnt {
  font-size: 16px;
  text-align: center;
}
.table {
  width: 100%;
  font-size: 14px;
}
.red {
  color: #ff0000;
}
.mr10 {
  margin-right: 10px;
}
</style>
